package svc

import (
	"github.com/elastic/go-elasticsearch/v7"
	"github.com/zeromicro/go-zero/core/logx"
	"go-zero-project/services/project/rpc/internal/config"
	"go-zero-project/services/project/rpc/internal/initialize/elastic"
)

type ServiceContext struct {
	ElasticSearchClient *elasticsearch.Client
	Config              config.Config
}

func NewServiceContext(c config.Config) *ServiceContext {
	service := &ServiceContext{
		Config: c,
	}
	// 1.初始化elastic search 链接
	client, err := elastic.InitClient(c.ElasticSearch)
	if err != nil {
		logx.Errorf("init elastic search failed,cause:%s ...", err.Error())
		return service
	}
	service.ElasticSearchClient = client
	return service
}
